<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="realName">
        <el-input
          v-model="queryParams.realName"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职工号" prop="jobNumber">
        <el-input
          v-model="queryParams.jobNumber"
          placeholder="请输入职工号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="tel">
        <el-input
          v-model="queryParams.tel"
          placeholder="请输入手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="人员属性" prop="type">
        <el-select v-model="queryParams.type" filterable  placeholder="请选择">
          <el-option v-for="item in typeList"
                     :key="item.typeCode"
                     :label="item.typeName"
                     :value="item.typeCode"></el-option>
        </el-select>
      </el-form-item>
     <!-- <el-form-item label="身份证号" prop="idNumber">
        <el-input
          v-model="queryParams.idNumber"
          placeholder="请输入身份证号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <!--<el-form-item label="入职时间" prop="entryTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.entryTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择入职时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="退休时间" prop="retirementTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.retirementTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择退休时间">
        </el-date-picker>
      </el-form-item>-->
      <!--<el-form-item label="是否会员" prop="isMember">
        <el-input
          v-model="queryParams.isMember"
          placeholder="请输入是否会员"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--<el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:SysMiniUser:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:SysMiniUser:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:SysMiniUser:remove']"
        >删除</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-bangzhu"
          size="mini"
          @click="personnelSynchronization"
          v-hasPermi="['business:SysMiniUser:personnelSynchronization']"
        >人员信息同步</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-bangzhu"
          size="mini"
          @click="retirementSynchronization"
          v-hasPermi="['business:SysMiniUser:retirementSynchronization']"
        >退休信息同步</el-button>
      </el-col>
      <!--<el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:SysMiniUser:export']"
        >导出</el-button>
      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="SysMiniUserList" @selection-change="handleSelectionChange">
      <!--<el-table-column type="selection" width="55" align="center" />
      <el-table-column label="${comment}" align="center" prop="miniUserId" />
      <el-table-column label="openid" align="center" prop="openid" />
      <el-table-column label="昵称" align="center" prop="nickName" />
      <el-table-column label="头像" align="center" prop="avatar" />-->
      <el-table-column label="姓名" align="center" prop="realName" />
      <el-table-column label="职工号" align="center" prop="jobNumber" />
      <el-table-column label="手机号" align="center" prop="tel" />
      <!--<el-table-column label="性别" align="center" prop="sex" />-->
      <el-table-column label="身份证号" align="center" prop="idNumber" />
      <el-table-column label="人员属性 " align="center" prop="type" >
        <template slot-scope="scope">
         <!-- 0 在职 1离退休 2大集体-->
          <span v-if="scope.row.type=='0'">在职</span>
          <span v-if="scope.row.type=='1'">离退休</span>
          <span v-if="scope.row.type=='2'">大集体</span>
        </template>
      </el-table-column>
      <el-table-column label="入职时间" align="center" prop="entryTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.entryTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="退休时间" align="center" prop="retirementTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.retirementTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否会员" align="center" prop="isMember" >
        <template slot-scope="scope">
            <span v-if="scope.row.isMember=='0'">是</span>
            <span v-if="scope.row.isMember=='1'">否</span>
        </template>
      </el-table-column>
      <el-table-column label="单位" align="center" prop="szdwmc" />
     <!-- <el-table-column label="${comment}" align="center" prop="remark" />-->
      <!--<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:SysMiniUser:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:SysMiniUser:remove']"
          >删除</el-button>
        </template>
      </el-table-column>-->
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

   <!-- &lt;!&ndash; 添加或修改小程序用户对话框 &ndash;&gt;
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="openid" prop="openid">
          <el-input v-model="form.openid" placeholder="请输入openid" />
        </el-form-item>
        <el-form-item label="昵称" prop="nickName">
          <el-input v-model="form.nickName" placeholder="请输入昵称" />
        </el-form-item>
        <el-form-item label="头像" prop="avatar">
          <el-input v-model="form.avatar" placeholder="请输入头像" />
        </el-form-item>
        <el-form-item label="手机号" prop="tel">
          <el-input v-model="form.tel" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="姓名" prop="realName">
          <el-input v-model="form.realName" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="职工号" prop="jobNumber">
          <el-input v-model="form.jobNumber" placeholder="请输入职工号" />
        </el-form-item>
        <el-form-item label="身份证号" prop="idNumber">
          <el-input v-model="form.idNumber" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="入职时间" prop="entryTime">
          <el-date-picker clearable size="small"
            v-model="form.entryTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择入职时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="退休时间" prop="retirementTime">
          <el-date-picker clearable size="small"
            v-model="form.retirementTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择退休时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否会员 0 是 1否" prop="isMember">
          <el-input v-model="form.isMember" placeholder="请输入是否会员 0 是 1否" />
        </el-form-item>
        <el-form-item label="单位ID" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入单位ID" />
        </el-form-item>
        <el-form-item label="${comment}" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入${comment}" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>-->
  </div>
</template>

<script>
import { listSysMiniUser, getSysMiniUser, delSysMiniUser, addSysMiniUser, updateSysMiniUser,personnelSynchronization,retirementSynchronization } from "@/api/user/SysMiniUser";

export default {
  name: "SysMiniUser",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 小程序用户表格数据
      SysMiniUserList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        openid: null,
        nickName: null,
        avatar: null,
        tel: null,
        sex: null,
        realName: null,
        jobNumber: null,
        idNumber: null,
        type: null,
        entryTime: null,
        retirementTime: null,
        isMember: null,
        deptId: null,
      },
      typeList:[
        {"typeCode":"0","typeName":"在职"},
        {"typeCode":"1","typeName":"离退休"},
        {"typeCode":"2","typeName":"大集体"},
      ],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询小程序用户列表 */
    getList() {
      this.loading = true;
      listSysMiniUser(this.queryParams).then(response => {
        this.SysMiniUserList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    personnelSynchronization(){
      personnelSynchronization().then(response => {
        this.$modal.msgSuccess("同步成功");
        this.getList();
      });
    },
    retirementSynchronization(){
      retirementSynchronization().then(response => {
        this.$modal.msgSuccess("同步成功");
        this.getList();
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        miniUserId: null,
        openid: null,
        nickName: null,
        avatar: null,
        tel: null,
        sex: null,
        realName: null,
        jobNumber: null,
        idNumber: null,
        type: null,
        entryTime: null,
        retirementTime: null,
        isMember: null,
        deptId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.miniUserId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加小程序用户";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const miniUserId = row.miniUserId || this.ids
      getSysMiniUser(miniUserId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改小程序用户";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.miniUserId != null) {
            updateSysMiniUser(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSysMiniUser(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const miniUserIds = row.miniUserId || this.ids;
      this.$modal.confirm('是否确认删除小程序用户编号为"' + miniUserIds + '"的数据项？').then(function() {
        return delSysMiniUser(miniUserIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/SysMiniUser/export', {
        ...this.queryParams
      }, `SysMiniUser_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
